package com.liuyou.weather4;

import java.util.ArrayList;

public class WeatherData {
    private final ArrayList<WebsiteObserver> websiteObservers;
    double temperature;
    double pressure;
    double humidity;

    public WeatherData() {
        websiteObservers = new ArrayList<WebsiteObserver>();
    }

    public WeatherData(double temperature, double pressure, double humidity) {
        this.temperature = temperature;
        this.pressure = pressure;
        this.humidity = humidity;
        websiteObservers = null;
    }

    public void setTemperature(double temperature) {
        this.temperature = temperature;
    }

    public void setPressure(double pressure) {
        this.pressure = pressure;
    }

    public void setHumidity(double humidity) {
        this.humidity = humidity;
    }

    @Override
    public String toString() {
        return "WeatherData{" +
                "temperature=" + temperature +
                ", pressure=" + pressure +
                ", humidity=" + humidity +
                '}';
    }

    public void registerObserver(WebsiteObserver websiteObserver) {
        assert websiteObservers != null;
        websiteObservers.add(websiteObserver);
    }

    public void removeObserver(WebsiteObserver websiteObserver) {
        websiteObservers.remove(websiteObserver);
    }

    public void notifyObserver() {
        for (WebsiteObserver websiteObserver : websiteObservers) {
            websiteObserver.update(this);
        }
    }
}
